package compiler;

import java.util.ArrayList;

import pointAndLine.Line;
import pointAndLine.Point;

import returnTypes.Status;

import wall.Wall;

public class CreateWall implements Create{
	public Object ExecutCommand(ArrayList<String> toDo)
	{
		
		String name=toDo.get(0);
		String pointName1=toDo.get(2).substring(0, toDo.get(2).length()-1);
		String pointName2=toDo.get(3);
		Point p1=null;
		Point p2=null;
		for(int i=0;i<Compiler.allPoints.size();i++)
		{
			if (Compiler.allPoints.get(i).getPointName().equals(pointName1))
				if (Compiler.allPoints.get(i).getState()==Status.FREE){
					p1=Compiler.allPoints.get(i);
					}
			if (Compiler.allPoints.get(i).getPointName().equals(pointName2))
				if (Compiler.allPoints.get(i).getState()==Status.FREE){
					p2=Compiler.allPoints.get(i);
					}
		}
		Wall returnWall=null;
		if ((p1!=null) && (p2!=null)){
			returnWall=new Wall(new Line(p1,p2));	
		returnWall.setName(name);
		returnWall.setState(Status.FREE);}
		return returnWall;
	}
}
